-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend bitset functionallity #28
Extend bitset functionallity #28
Conversation
|
3452006
to
9109877
Compare
Done. I've also switched to binary literals in the unit tests, which are easier to read, and renamed the type alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at enumUtils.h and found it lacking.
What exactly do you need? The idea was to keep it simple and I feel that the templated approach of global operators might increase compile times more than the previous approach using the types directly. But the opposite might also be the case 🤷
Besides that I do like the functions, especially the set
with a bool param sounds useful (i.e. "set or clear")
However we may additionally need a type for a bitset distinguished from the bits-enum, see e.g. the isSet
function where this might be relevant. If not it should really behave like regular bitsets, i.e. include the suggested change to isSet
Template instantiation is the expensive operation to be concerned with. The mere existence isn't worth fretting about.
I don't know what you mean by "regular bitset". A bitset to me is |
Exactly: You added
The pattern: A set of bits. Usually an unsigned integer. |
You're right, of course. SFINAE isn't magic. We could also do:
Then
Ah, I've seen that during my search just now. |
Add new operator overloads to enhance the functionality of bitsets, and introduce a type trait that enables enums to opt in to being used as bitsets.
9109877
to
bd4df9e
Compare
AFAIK it will still instantiate the templates until SFINAE discards them as it has to consider all possibly matching functions and the compiler can't know that those new operators don't match (better) until it instantiated them (up to the SFINAE part) Anyway: I believe the impact (if any) is small enough that this is worth it. So I'd go with the current solution as the namespacing of the operators would make it worse to use in e.g. default parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the return type for the modify-assign operators
They are still correct. :-) |
The change-assign operators should return a reference to the assigned-to object, same as the assign operator, shouldn't they?
|
Thanks for checking! That does make a lot more sense even though clangd keeps insisting it deduces as |
Implement utility functions to set, clear, toggle, and query a bitset for more concise code.
bd4df9e
to
def6a38
Compare
def6a38
to
327c17c
Compare
@Flow86 Turns out I missed that this Boost macro was added in Boost 1.71 but we still support(ed) 1.69 However 1.71 is the default for Ubuntu 20.04 If you don't mind I'll update all our usage (CI & CMake) to required Boost 1.71+ |
I went ahead with the PR anyway. (This is for Return-To-The-Roots/s25client#1602.)
I've introduced a local macro
ENUM_UTILS_NODISCARD
but think it might be useful to addNODISCARD
orRTTR_NODISCARD
globally. If so, where should I put it? A new file?compile.h
,macros.h
,future.h
, ...